import os 
import sys
import json
def readfile(fileName):
    s=""
    with open(fileName,encoding="UTF-8") as file:    
        s=file.read()
    return s
def main():
    print("a")

if len(sys.argv)>2 :
    fileName=sys.argv[1]
    toFileName=sys.argv[2]
    #print(fileName)
    #print(toFileName)
    #os._exit(0)
else:
    fileName="test.txt"
    toFileName="test.jpg"
s=readfile(fileName=fileName)
l=[]
for i in s.split("|||"):
    if i.strip()!='':
        print(i)
        print("=====>\r\n")
        l.append(json.loads(i))
if(len(l)>0):
    allCount=l[len(l)-1]['count']
aa=[]
for i in range(0,allCount):
    for ii in l:
        print(ii["index"])
        if ii["index"]==i:
            print(i)
            aa.append(ii['imgdata'][len('7600320000'):-(len('7600320000'))])
print(aa)
ss=''.join(aa).strip()
#print(ss)
a=bytes.fromhex(ss)
with open(toFileName, 'wb') as file:
    file.write(a)